﻿using System.Linq;
using System.ComponentModel;

namespace hbse.Entities
{
    public class EntityBindable : Entity, INotifyPropertyChanged, IDataErrorInfo
    {
 

        public virtual event PropertyChangedEventHandler PropertyChanged;

    

        protected virtual void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public virtual bool IsNew()
        {
            return IsTransient();
        }

        public virtual bool IsValid()
        {
            return ApplicationContext.Validator.IsValid(this);
        }

    

        string IDataErrorInfo.this[string columnName]
        {
            get
            {
                return string.Concat(
                    ApplicationContext.Validator
                    .ValidatePropertyValue(this, columnName)
                    .Select(iv => iv.Message + "\n").ToArray()).Trim();
            }
        }

        string IDataErrorInfo.Error
        {
            get
            {
                return string.Concat(
                    ApplicationContext.Validator
                    .Validate(this)
                    .Select(iv => iv.Message + "\n").ToArray()).Trim();
            }
        }

        
    }
}
